//
//  ShopAttentionCell.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/4.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "ShopAttentionCell.h"

@interface ShopAttentionCell ()

@property (nonatomic, strong) UIImageView * headImage;
@property (nonatomic, strong) UILabel     * nameLabel;
@property (nonatomic, strong) UIView      * tagView;
@property (nonatomic, strong) UILabel     * detailLabel;
@property (nonatomic, strong) UILabel     * serveLabel;
@property (nonatomic, strong) UILabel     * moneyLabel;


@end

@implementation ShopAttentionCell

-(void)setDesignListDataModel:(DesignListDataModel *)designListDataModel
{
    _designListDataModel = designListDataModel;
    
    self.nameLabel.text = designListDataModel.name;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:designListDataModel.person_img] placeholderImage:nil options:SDWebImageRetryFailed];
    self.moneyLabel.text = [NSString stringWithFormat:@"%@",designListDataModel.price];
    self.serveLabel.text = designListDataModel.design_name;
    NSString *volumeNum = [NSString stringWithFormat:@"成交%@笔|",designListDataModel.volume];
    NSString *zongfenNum = [NSString stringWithFormat:@"服务评分：%@分|",designListDataModel.zongfen];
    NSString *distanceNum = [NSString stringWithFormat:@"%@km",designListDataModel.distance];
    self.detailLabel.text = [[volumeNum stringByAppendingString:zongfenNum] stringByAppendingString:distanceNum];
    for (UIView *subView in self.tagView.subviews) {
        [subView removeFromSuperview];
    }
    CGFloat x = 0.0f;
    for (int i = 0; i < _designListDataModel.labels.count; i++) {
        UILabel *tagLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 0, kGetStringWidth(_designListDataModel.labels[i][@"name"], CGSizeMake(MAXFLOAT, ScreenX375(15)), Kfont(10)) + ScreenX375(10), ScreenX375(15))];
        tagLabel.text = _designListDataModel.labels[i][@"name"];
        tagLabel.textColor = ThemeColor;
        tagLabel.font = Kfont(10);
        tagLabel.textAlignment = NSTextAlignmentCenter;
        tagLabel.layer.borderColor = ThemeColor.CGColor;
        tagLabel.layer.borderWidth = 1;
        tagLabel.layer.cornerRadius = ScreenX375(7.5);
        tagLabel.clipsToBounds = YES;
        [self.tagView addSubview:tagLabel];
        
        x += kGetStringWidth(_designListDataModel.labels[i][@"name"], CGSizeMake(MAXFLOAT, ScreenX375(15)), Kfont(10)) + ScreenX375(15);
    }
}


-(void)setShopInfoAttentionModel:(ShopInfoAttentionModel *)shopInfoAttentionModel {
    _shopInfoAttentionModel = shopInfoAttentionModel;
    
    self.nameLabel.text = shopInfoAttentionModel.name;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:shopInfoAttentionModel.logo] placeholderImage:nil options:SDWebImageRetryFailed];
    self.moneyLabel.text = [NSString stringWithFormat:@"%@元",shopInfoAttentionModel.price];
    self.serveLabel.text = shopInfoAttentionModel.design_name;
    self.detailLabel.text = shopInfoAttentionModel.intro;
}

+ (ShopAttentionCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"ShopAttentionCell";
    ShopAttentionCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ShopAttentionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    self.headImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(17), ScreenX375(81), ScreenX375(81))];
    self.headImage.layer.cornerRadius = ScreenX375(40.5);
    self.headImage.clipsToBounds = YES;
    [self addSubview:self.headImage];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(104), ScreenX375(14), ScreenX375(160), ScreenX375(16))];
    self.nameLabel.textColor = REXADECIMALCOLOR(@"#333333");
    self.nameLabel.font = Kfont(14);
    [self addSubview:self.nameLabel];
    
    self.tagView = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(104), ScreenX375(37), SCREEN_WIDTH - ScreenX375(117), ScreenX375(15))];
    [self addSubview:self.tagView];
    
    self.detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(104), ScreenX375(60), SCREEN_WIDTH - ScreenX375(139), ScreenX375(14))];
    self.detailLabel.textColor = REXADECIMALCOLOR(@"#999999");
    self.detailLabel.font = Kfont(12);
    [self addSubview:self.detailLabel];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(104), ScreenX375(81), ScreenX375(30), ScreenX375(15))];
    label.text = @"服务";
    label.textColor = ThemeColor;
    label.font = Kfont(10);
    label.textAlignment = NSTextAlignmentCenter;
    label.layer.cornerRadius = ScreenX375(7.5);
    label.layer.borderColor = ThemeColor.CGColor;
    label.layer.borderWidth = 1;
    [self addSubview:label];
    
    self.serveLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(140), ScreenX375(80), ScreenX375(140), ScreenX375(16))];
    self.serveLabel.textColor = ThemeColor;
    self.serveLabel.font = Kfont(12);
    [self addSubview:self.serveLabel];
    
    self.moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(113), ScreenX375(80), ScreenX375(100), ScreenX375(22))];
    self.moneyLabel.textColor = ThemeColor;
    self.moneyLabel.font = Kfont(14);
    self.moneyLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.moneyLabel];
    
    self.collctBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(31), ScreenX375(15), ScreenX375(19), ScreenX375(18))];
    [self.collctBtn setImage:[UIImage imageNamed:@"关注店铺-关注"] forState:UIControlStateNormal];
    [self.collctBtn addTarget:self action:@selector(cancelConcern) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.collctBtn];
    
    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(111) - 0.5, SCREEN_WIDTH - ScreenX375(26), 0.5)];
    line.image = [UIImage imageNamed:@"虚线"];
    [self addSubview:line];
}

- (void)cancelConcern {
    if (_cancelConcernClick) {
        _cancelConcernClick();
    }
}

@end
